using UnityEngine;
using System.Collections;

public class Weapon : MonoBehaviour {
	
	public float minAttackPower;
	public float maxAttackPower;
	
	public float speed;
	public float cooldown;
	
	[HideInInspector]
	public Skill currentSkill;
	public Skill[] skills;
	
	public ParticleEmitter HitEffect;
	// Use this for initialization
	void Awake () {
		
		currentSkill = null;
		
		if(skills == null || skills.Length == 0)
		{
			print("Weapon: " + gameObject.name + " has no skillset in Skill[] skills ");
			return;
		}
		
		//make copy from pool
		currentSkill = skills[0];
		
		//findSkillFromPool(SkillName);
		
		if(currentSkill != null)
		{
			print("WeaponName: " + gameObject.name + " has skill " + currentSkill.gameObject.name);
		}else{
			print("This Weapon has no skill setting.");
			
			
		}
		testYield();
		
	}
	public void findSkillFromPool(string skillName)
	{
		GameObject skillPool = GameObject.Find("SkillPool");
		
		Skill[] skillPoolSkills = skillPool.transform.GetComponentsInChildren<Skill>();
		
		foreach(Skill skill in skillPoolSkills)
		{
			if(skill.gameObject.name == skillName)
			{
				currentSkill = skill;
				break;
			}
		}
	}
	// Update is called once per frame
	void Update () {
		
	}
	IEnumerator testYield()
	{
		
		for(int i = 0;i<50;i++)
		{
			yield return new WaitForSeconds(5.0f);
			HitEffect.emit = false;
			yield return new WaitForSeconds(5.0f);
			HitEffect.emit = true;
		}
		
	}
}
